package com.youi.service.impl;

import com.youi.dao.PurchasehistoryDao;
import com.youi.entity.Purchasehistory;
import com.youi.entity.User;
import com.youi.service.PurchasehistoryService;
import com.youi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class PurchasehistoryServiceImpl extends BaseServiceImpl<Purchasehistory> implements PurchasehistoryService {

    private PurchasehistoryDao purchasehistoryDao;

    @Autowired
    private UserService userService;

    @Autowired
    public void setfaultRecordDao(PurchasehistoryDao purchasehistoryDao) {
        this.purchasehistoryDao = purchasehistoryDao;
        super.setBaseDAO(purchasehistoryDao);
    }

    @Override
    public List<Purchasehistory> getPurchasehistoryMsg(List<Purchasehistory> purchasehistoryList) {
        if (purchasehistoryList != null && purchasehistoryList.size() > 0) {
            for (Purchasehistory purchasehistory : purchasehistoryList) {
                User user = userService.get(purchasehistory.getUserId());
                if (user != null) {
                    purchasehistory.setNickName(user.getNickName());
                    purchasehistory.setUserImg(user.getImg());
                }
            }
        }
        return purchasehistoryList;
    }

	@Override
	public List<Purchasehistory> listNoRepeatPurchaseUser(Map<String, Object> param) {
		return purchasehistoryDao.listNoRepeatPurchaseUser(param);
	}
}